package com.jrfid.smartcabinet.demo.ui.add_nfc

import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.blankj.utilcode.util.ToastUtils
import com.jrfid.smartcabinet.demo.R
import com.jrfid.smartcabinet.demo.base.BaseFragment
import com.jrfid.smartcabinet.demo.databinding.AddNfcFragmentBinding
import com.jrfid.smartcabinet.demo.ui.MainViewModel
import java.util.*
import kotlin.concurrent.timer

class AddNFCFragment : BaseFragment<AddNfcFragmentBinding, AddNFCViewModel>(AddNFCViewModel::class.java) {

    companion object {
        fun newInstance() = AddNFCFragment()
    }

    override fun getLayoutId(): Int = R.layout.add_nfc_fragment
    private val mainViewModel by activityViewModels<MainViewModel>()
    private var readICCardTimer: Timer? = null
    private var i = 0
    override fun setData() {
//        mainViewModel.currentICCardNo.observe(this, {
//            if (it == null) {
//                ToastUtils.showShort("读取失败")
//            } else {
//                ToastUtils.showShort("读取到卡号：${it}")
//            }
//        })
//        readICCardTimer = timer(null, false, 0L, 4000L) {
//            if (i % 2 == 0) {
//                mainViewModel.readICCard.postValue("/dev/bus/usb/002/003")
//            } else {
//                mainViewModel.readICCard.postValue("/dev/bus/usb/002/005")
//            }
//            i++
//        }
    }

    override fun onDestroy() {
        super.onDestroy()
        readICCardTimer?.cancel()
    }

}